package com.ygqh.baby.quartz;

import org.apache.log4j.Logger;
import org.quartz.SchedulerException;
import org.springframework.stereotype.Component;

import com.ygqh.baby.ao.Message;
import com.ygqh.baby.po.ScheduleJob;

@Component("scheduleJobApi")
public class ScheduleJobApi {
	protected final Logger logger = Logger.getLogger(this.getClass());

	public Message addJob(ScheduleJob scheduleJob) {
		try {
			QuartzManager.addJob(scheduleJob);
		} catch (SchedulerException e) {
			e.printStackTrace();
			return Message.error(e.getMessage(), e);
		}
		return Message.success(null);
	}

	public Message updateJobCron(ScheduleJob scheduleJob) {
		try {
			QuartzManager.updateJobCron(scheduleJob);
		} catch (SchedulerException e) {
			e.printStackTrace();
			return Message.error(e.getMessage(), e);
		}
		return Message.success(null);
	}

	public Message deleteJob(ScheduleJob scheduleJob) {
		try {
			Boolean job = QuartzManager.deleteJob(scheduleJob);
		} catch (SchedulerException e) {
			e.printStackTrace();
			return Message.error(e.getMessage(), e);
		}
		return Message.success(null);
	}

}
